<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>hexo+nginx服务器上部署博客(二) | Cquang博客</title><meta name="keywords" content="ssh,git,hexo"><meta name="author" content="Cai XianQuan"><meta name="copyright" content="Cai XianQuan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="完成hexo博客部署到VPS上，并且能够实现在新电脑上继续编辑博客并发布部署。">
<meta property="og:type" content="article">
<meta property="og:title" content="hexo+nginx服务器上部署博客(二)">
<meta property="og:url" content="https://xquan123.gitee.io/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/index.html">
<meta property="og:site_name" content="Cquang博客">
<meta property="og:description" content="完成hexo博客部署到VPS上，并且能够实现在新电脑上继续编辑博客并发布部署。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://xquan123.gitee.io/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C%E9%A6%96%E9%A1%B5.jpg">
<meta property="article:published_time" content="2020-07-03T06:18:25.000Z">
<meta property="article:modified_time" content="2021-01-08T02:25:30.808Z">
<meta property="article:author" content="Cai XianQuan">
<meta property="article:tag" content="git">
<meta property="article:tag" content="hexo">
<meta property="article:tag" content="ssh">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://xquan123.gitee.io/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C%E9%A6%96%E9%A1%B5.jpg"><link rel="shortcut icon" href="/blog/img/favicon1.png"><link rel="canonical" href="https://xquan123.gitee.io/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin="crossorigin"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web"><script>var GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2021-01-08 10:25:30'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><link rel="stylesheet" href="/css/VolantisTags.css"><meta name="generator" content="Hexo 5.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/blog/img/%E5%A4%B4%E5%83%8F.gif" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">22</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">33</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 享受时光</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/blog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li></ul></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(/blog/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C%E9%A6%96%E9%A1%B5.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Cquang博客</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 享受时光</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/blog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li></ul></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">hexo+nginx服务器上部署博客(二)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-07-03T06:18:25.000Z" title="发表于 2020-07-03 14:18:25">2020-07-03</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-01-08T02:25:30.808Z" title="更新于 2021-01-08 10:25:30">2021-01-08</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/hexo%E5%8D%9A%E5%AE%A2/">hexo博客</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>11分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="本章重点"><a href="#本章重点" class="headerlink" title="本章重点"></a>本章重点</h1><ul>
<li>ssh免密登录</li>
<li>创建git仓库，配置hooks</li>
<li>安装hexo</li>
<li>部署hexo并发布</li>
<li>在新电脑上继续使用hexo</li>
</ul>
<h1 id="ssh免密登录"><a href="#ssh免密登录" class="headerlink" title="ssh免密登录"></a>ssh免密登录</h1><p>服务器由于是在国外，使用密码登录容易遭受攻击，服务器上现有两个账号，一个root账号和一个普通用户账号caixianquan，将两个账号都设置为ssh免密登录，更具安全性，也在git连接远程仓库时不会有问题。</p>
<h2 id="root下免密登录"><a href="#root下免密登录" class="headerlink" title="root下免密登录"></a>root下免密登录</h2><ul>
<li><p>首先需要生成公钥和私钥，在<code>root账户</code>下输入：<code>ssh-keygen -t rsa</code>，然后如下操作。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">Generating public/private rsa key pair.  </span><br><span class="line">Enter file <span class="keyword">in</span> <span class="built_in">which</span> to save the key (/root/.ssh/id_rsa): 建议直接回车使用默认路径  </span><br><span class="line">Created directory <span class="string">&#x27;/root/.ssh&#x27;</span>  </span><br><span class="line">Enter passphrase (empty <span class="keyword">for</span> no passphrase): 输入密码短语（留空则直接回车）  </span><br><span class="line">Enter same passphrase again: 重复密码短语  </span><br><span class="line">Your identification has been saved <span class="keyword">in</span> /root/.ssh/id_rsa.  </span><br><span class="line">Your public key has been saved <span class="keyword">in</span> /root/.ssh/id_rsa.pub.  </span><br><span class="line">The key fingerprint is:  </span><br><span class="line">05:71:53:92:96:ba:53:20:55:15:7e:5d:59:85:32:e4 root@<span class="built_in">test</span>  </span><br><span class="line">The key<span class="string">&#x27;s randomart image is:  </span></span><br><span class="line"><span class="string">+--[ RSA 2048]----+  </span></span><br><span class="line"><span class="string">| o o .. |  </span></span><br><span class="line"><span class="string">| . o oo.+ . |  </span></span><br><span class="line"><span class="string">| o.+... = |  </span></span><br><span class="line"><span class="string">| ...o |  </span></span><br><span class="line"><span class="string">| o S |  </span></span><br><span class="line"><span class="string">| . |  </span></span><br><span class="line"><span class="string">| |  </span></span><br><span class="line"><span class="string">| |  </span></span><br><span class="line"><span class="string">| |  </span></span><br><span class="line"><span class="string">+--------------------+</span></span><br></pre></td></tr></table></figure>
<p>此时在/root/.ssh/目录下生成了2个文件，id_rsa为私钥，id_rsa.pub为公钥。私钥自己下载到本地电脑妥善保存（丢了服务器可就没法再登陆了），为安全，建议删除服务器端的私钥。公钥则可以任意公开。【这里我保存私钥到坚果云的我的服务器目录下，删除了服务器上面的私钥】</p>
</li>
<li><p>使用以下命令将公钥导入到VPS：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /root/.ssh/id_rsa.pub &gt;&gt; /root/.ssh/authorized_keys</span><br></pre></td></tr></table></figure>
<div class="note info flat"><p>如果没有.ssh目录和authorized_keys文件，可以手动创建</p>
</div>
</li>
<li><p>修改 /etc/ssh/sshd_config 文件，找到其中这几行配置注释，并指定需要的值：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#允许root认证登录</span></span><br><span class="line">PermitRootLogin yes</span><br><span class="line"><span class="comment">#允许密钥认证</span></span><br><span class="line">RSAAuthentication yes</span><br><span class="line">PubkeyAuthentication yes</span><br><span class="line"><span class="comment">#默认公钥存放的位置</span></span><br><span class="line">AuthorizedKeysFile .ssh/authorized_keys</span><br></pre></td></tr></table></figure></li>
<li><p>保存后重启SSH服务。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart sshd</span><br></pre></td></tr></table></figure>
<div class="note info flat"><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">如果没有RSAAuthentication这行注释或者配置项，就不用理会，这是因为：</span><br><span class="line">为什么在 CentOS7.4 的配置文件中没有 RSAAuthentication 这一行？</span><br><span class="line"></span><br><span class="line">CentOS7.4相对于之前版本，做了一些与sshd相关的安全更新来加强sshd的安全性。其中之一就是弃用RSAAuthentication支持。从CentOS7.3升级上来的用户会在升级时被告知这一变化。</span><br><span class="line">作为从CentOS7.4直接开始使用，也没有阅读过发行说明的我，自然是不清楚这一改动。</span><br><span class="line"></span><br><span class="line">看到这里又产生了新的问题：</span><br><span class="line">什么是弃用 RSAAuthentication 支持，明明还可以使用密钥对进行ssh登录，是默认开启不允许关闭的意思吗？</span><br><span class="line"></span><br><span class="line">要回答这个问题，首先要了解ssh通讯协议，目前SSH的通讯协议分为第一代和第二代，不用多说第二代有更多功能、选项、和更高的安全性，它是在2006 正式由IETF发表，至今已有十年。由于两代SSH协定并不兼容，我们只能二选其一，CentOS 7的SSH预设使用第二代协定，所以无需做任何设定。</span><br><span class="line">在同时支持这两个协议的系统中，可以通过 /etc/ssh/sshd_config 配置文件中的</span><br><span class="line">Protocol 2</span><br><span class="line">来制定使用哪一个版本。</span><br><span class="line"></span><br><span class="line">RSAAuthentication （rsa认证）是只支持第1代ssh通讯协议使用的配置项，在CentOS7.4中被废除了，而且前面提到过CentOS7开始预设使用第二代通讯协议，在CentOS7.4中没有找到指定协议版本的配置行，个人猜测是CentOS7.4全面抛弃第1代协议。</span><br><span class="line"></span><br><span class="line">第2代ssh通讯协议的密钥验证选项是</span><br><span class="line"><span class="comment">#PubkeyAuthentication yes</span></span><br><span class="line"></span><br><span class="line">这个选项默认是注释掉的，并且是默认开启的，因此我们在使用第二代ssh通讯协议时不需要再去纠结 RSAAuthentication 选项了，在CentOS7.4中其强行添加 RSAAuthentication 配置会触发系统对它的废除提示。</span><br><span class="line"></span><br><span class="line">reprocess config line 38: Deprecated option RSAAuthentication</span><br><span class="line">看到这里所有的疑惑就都解开了，将这个小坑记录下来希望后来的同学能少走弯路。</span><br></pre></td></tr></table></figure></div>
<p>在使用SSH Key登录验证成功后，还是为了安全，建议关闭root用户使用密码登陆，关闭的方法如下：</p>
</li>
</ul>
<p>修改SSH的配置文件/etc/ssh/sshd_config，找到下面1行：<br><code>PasswordAuthentication yes</code><br>修改为：<br><code>PasswordAuthentication no</code><br>保存后重启SSH服务。<br><code>systemctl restart sshd</code></p>
<div class="note success flat"><p>之后只要在个人电脑上下载坚果云上的私钥，使用该私钥即可登录服务器root账号。</p>
</div>

<h2 id="普通账户下免密登录"><a href="#普通账户下免密登录" class="headerlink" title="普通账户下免密登录"></a>普通账户下免密登录</h2><ul>
<li><del>之前在root下已经生成了私钥和公钥，直接将公钥复制到普通账户下的.ssh目录下的authorized_keys文件下，如果没有该目录及文件则手动创建。</del></li>
<li><font color=red size=3><strong><em>上述方法有可能会报权限拒绝问题【使用私钥ssh连接】</em></strong></font></li>
</ul>
<ol>
<li>git bash中ssh连接时报如下错误：Permission denied (publickey,gssapi-keyex,gssapi-with-mic).</li>
<li>在xshell使用私钥连接时报错：所选的用户密钥未在远程主机上注册</li>
<li>登录目标服务器查看sshd日志信息，日志信息目录为，/var/log/secure，有如下错误：Jul 22 14:20:33 v138020.go sshd[4917]: Authentication refused: bad ownership or modes for directory /home/xinhailong</li>
<li>原因：sshd为了安全，对属主的目录和文件权限有所要求。如果权限不对，则ssh的免密码登陆不生效。用户目录权限为 755 或者 700，就是不能是77x。.ssh目录权限一般为755或者700。rsa_id.pub 及authorized_keys权限一般为644，rsa_id权限必须为600</li>
<li>如果是手动创建的.ssh和authorized_keys文件时就要安装以上重新配置权限即可。参考地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/kmhysoft/article/details/70432633">ssh免密码登陆设置时Authentication refused: bad ownership or modes错误解决方法</a></li>
</ol>
<ul>
<li>在本地windows下在使用ssh的客户端软件中修改配置文件，如git工具，在安装目录下有ssh的配置文件，如下：<br><img src="1%E3%80%81%E4%BF%AE%E6%94%B9ssh%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6.png" alt="修改ssh客户端配置文件"><br>修改ssh_config文件两处地方【如果前有#注释，去掉】：<br><img src="2%E3%80%81%E5%A1%AB%E5%85%A5%E7%A7%81%E9%92%A5%E5%92%8C%E4%BF%AE%E6%94%B9%E7%AB%AF%E5%8F%A3%E5%8F%B7.png" alt="填入私钥和修改端口号"><div class="note primary flat"><p>如果有需要就修改端口号，否则默认是22端口登录，且在git连接远程仓库push时也是用默认端口，无法指定【暂未知】</p>
</div>

</li>
</ul>
<p>这样就可以在git bash中使用ssh免密登录普通账号，使用命令如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh 用户名@ip地址</span><br></pre></td></tr></table></figure>
<h1 id="创建git仓库，配置hooks"><a href="#创建git仓库，配置hooks" class="headerlink" title="创建git仓库，配置hooks"></a>创建git仓库，配置hooks</h1><div class="note warning flat"><p>注意在普通用户下操作</p>
</div>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~</span><br><span class="line">mkdir repos</span><br><span class="line"><span class="built_in">cd</span> repos</span><br><span class="line">git init --bare blog.git	<span class="comment">#创建一个裸仓库</span></span><br><span class="line">vim blog.git/hooks/post-receive	<span class="comment">#直接编辑post-receive文件【没有则自动创建】</span></span><br></pre></td></tr></table></figure>
<p>输入以下内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line">git --work-tree=/opt/blog --git-dir=/home/caixianquan/repos/blog.git checkout -f</span><br></pre></td></tr></table></figure>
<div class="note warning flat"><p>/opt/blog文件夹最好已经创建存在，未测试不存在情况</p>
</div>

<p>保存退出后授予文件权限：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod +x blog.git/hooks/post-receive</span><br></pre></td></tr></table></figure>
<h1 id="安装Hexo"><a href="#安装Hexo" class="headerlink" title="安装Hexo"></a>安装Hexo</h1><div class="note info flat"><p>npm 的仓库在国外，这就意味着下载可能非常慢，或者不可以下载。因此我的解决方案是用淘宝的镜像源替代。</p>
<p>替代方案很简单只需要在命令行输入 <code>npm install -g cnpm --registry=https://registry.npm.taobao.org</code> 即可，然后每次需要使用 <code>npm</code> 命令时，将 <code>npm</code> 换成 <code>cnpm</code> 即可。</p>
</div>

<h2 id="安装hexo"><a href="#安装hexo" class="headerlink" title="安装hexo"></a>安装hexo</h2><p><code>npm install -g hexo-cli</code><br>安装完成后依旧使用 <code>hexo -v</code> 查看以下版本号。<br><img src="3%E3%80%81%E6%9F%A5%E7%9C%8Bhexo%E7%89%88%E6%9C%AC.png" alt="查看hexo版本"></p>
<h2 id="初始化一个-Hexo-博客"><a href="#初始化一个-Hexo-博客" class="headerlink" title="初始化一个 Hexo 博客"></a>初始化一个 Hexo 博客</h2><p>在任意位置创建一个文件夹，hexo博客将出现在这个文件夹。在该文件夹下右键使用git bash打开，输入命令<code>hexo init .</code>，然后程序会自动克隆一个 Hexo 项目到当前目录。</p>
<div class="note warning flat"><p>注意有一个点代表当前文件夹！！</p>
</div>

<p>查看hexo博客，通过<code>hexo s</code>启动本地服务器，访问：<a href="http://localhost:4000即可查看博客。">http://localhost:4000即可查看博客。</a></p>
<h2 id="安装主题，hexo优化"><a href="#安装主题，hexo优化" class="headerlink" title="安装主题，hexo优化"></a>安装主题，hexo优化</h2><p>可以修改默认主题，并制定个性化界面，这里不展开叙述。</p>
<h1 id="部署hexo并发布"><a href="#部署hexo并发布" class="headerlink" title="部署hexo并发布"></a>部署hexo并发布</h1><ul>
<li>配置博客根目录下的<code>_config.yml</code> 文件<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">deploy:</span><br><span class="line">  <span class="built_in">type</span>: git   <span class="comment">#必须为git</span></span><br><span class="line">  repo: caixianquan@www.caixianquan.tk:/home/caixianquan/repos/blog.git  <span class="comment">#Git仓库</span></span><br><span class="line">  branch: master <span class="comment">#分支</span></span><br></pre></td></tr></table></figure></li>
<li>在 <code>package.json</code> 中添加 npm 脚本<br>【暂且添加一行，后面同步hexo源文件时再修改】<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;scripts&quot;</span>: &#123;</span><br><span class="line">   <span class="string">&quot;deploy&quot;</span>: <span class="string">&quot;hexo clean &amp;&amp; hexo g -d&quot;</span>,</span><br><span class="line">   <span class="string">&quot;start&quot;</span>: <span class="string">&quot;hexo clean &amp;&amp; hexo g &amp;&amp; hexo s&quot;</span></span><br><span class="line"> &#125;,</span><br></pre></td></tr></table></figure>
以后本地调试使用<code>npm start</code>,即可调用以上命令，快速调试，部署到服务器时使用命令<code>npm deploy</code>。</li>
</ul>
<h1 id="在新电脑上继续使用hexo"><a href="#在新电脑上继续使用hexo" class="headerlink" title="在新电脑上继续使用hexo"></a>在新电脑上继续使用hexo</h1><h2 id="说明"><a href="#说明" class="headerlink" title="说明"></a>说明</h2><p>上传到服务器上的hexo.git仓库，后面用没安装过hexo的电脑可以直接clone下来，安装nodejs和hexo，就可以使用<br>参考：<a target="_blank" rel="noopener" href="https://www.jianshu.com/p/153490a029a5">迁移hexo到新电脑</a></p>
<h2 id="创建非裸仓库"><a href="#创建非裸仓库" class="headerlink" title="创建非裸仓库"></a>创建非裸仓库</h2><div class="note info flat"><p>尝试过在部署的时候使用的是非裸仓库，然后在这个仓库下新建一个分支来保存源文件，但这样会有一个问题，每次checkout时仓库中的文件会发生变化，很莫名其妙，为了尽量减少错误和麻烦，直接创建一个新的非裸仓库来保存源文件，而使用裸仓库来同步博客的资源文件。</p>
</div>

<div class="note warning flat"><p>以下最好在普通用户下操作</p>
</div>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~</span><br><span class="line"><span class="built_in">cd</span> repos</span><br><span class="line">mkdir hexo.git</span><br><span class="line"><span class="built_in">cd</span> hexo.git</span><br><span class="line">git init</span><br></pre></td></tr></table></figure>
<p>即可生成一个非裸仓库</p>
<h2 id="上传到远程仓库"><a href="#上传到远程仓库" class="headerlink" title="上传到远程仓库"></a>上传到远程仓库</h2><ul>
<li>先将远程仓库hexo.git克隆到本地，方便后续上传。在本地找一个文件夹右键点击git bash，执行以下命令</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> 用户名@服务器ip:/路径/.git</span><br></pre></td></tr></table></figure>
<div class="note info flat"><p>这里是需要服务器的用户名和密码，如果有免密登录，即可直接下载</p>
</div>

<ul>
<li><p>克隆后的本地仓库中除了.git文件夹其他删除，复制之前的博客源文件到该仓库中，除了.deploy_git文件夹，源文件应该包含一个.gitignore文件，如果没有，新建，加入以下内容</p>
<div class="note info flat"><p>.DS_Store<br>Thumbs.db<br>db.json<br><em>.log<br>node_modules/<br>public/<br>.deploy</em>/</p>
</div>     
<p><img src="7%E3%80%81%E6%8B%B7%E8%B4%9D%E6%BA%90%E6%96%87%E4%BB%B6%E5%88%B0%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93.png" alt="拷贝源文件到本地仓库"></p>
</li>
<li><p>如果使用到主题库，比如butterfly，会报如下错误：<br><img src="8%E3%80%81git%E4%BB%93%E5%BA%93%E5%B5%8C%E5%A5%97git%E4%BB%93%E5%BA%93%E6%8A%A5%E9%94%99.png" alt="git仓库嵌套git仓库报错"><br>那么需要删除掉clone下来的主题库的.git和.github文件夹<br><img src="11%E3%80%81clone%E4%B8%8B%E6%9D%A5%E7%9A%84%E4%B8%BB%E9%A2%98%E5%AD%98%E5%9C%A8.git%E5%92%8C.github%E6%96%87%E4%BB%B6%E5%A4%B9.png" alt="clone下来的主题存在.git和.github文件夹"><br>接着需要删除掉缓存的目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git rm --cached directory</span><br><span class="line">git add directory</span><br></pre></td></tr></table></figure>
<div class="note warning flat"><p>注：directory为子文件夹的路径。<br>但是执行git rm –cached directory时，提示</p>
<p>fatal: Unable to create ‘xx/.git/index.lock’: File exists.<br>执行<code>rm -f xx/.git/index.lock</code>后解决</p>
<p>参考地址：<a target="_blank" rel="noopener" href="https://www.cnblogs.com/howdop/p/5583342.html">git 无法添加文件夹下文件</a></p>
</div>
<p>而后，在本地仓库中提交一次</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git add .</span><br><span class="line">git commit –m <span class="string">&quot;add branch&quot;</span></span><br><span class="line">git push </span><br></pre></td></tr></table></figure>
<p>在push到远程仓库时，报如下错误：<br><img src="9%E3%80%81push%E6%97%B6%E6%9D%83%E9%99%90%E6%8B%92%E7%BB%9D.png" alt="push时权限拒绝"><br>原因可能是不是所在用户创建的仓库，修改所有者即可</p>
</li>
</ul>
<p>新的报错问题：<br><img src="10%E3%80%81%E6%8B%92%E7%BB%9Dpush.png" alt="拒绝push"><br>这是由于git默认拒绝了push操作，需要进行设置，修改【在服务器上的git仓库中】.git/config文件后面添加如下代码：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[receive]</span><br><span class="line">	denyCurrentBranch = ignore</span><br></pre></td></tr></table></figure>
<p>重新git push即可</p>
<div class="note primary flat"><p>若在服务器上看不到同步的文件，需要使用命令<code>git checkout master</code>进行切换分支</p>
</div> 

<h2 id="在新电脑上安装git和nodejs"><a href="#在新电脑上安装git和nodejs" class="headerlink" title="在新电脑上安装git和nodejs"></a>在新电脑上安装git和nodejs</h2><p>步骤省略，参考hexo安装过程，其中还要设置ssh免密登录</p>
<h2 id="安装hexo-1"><a href="#安装hexo-1" class="headerlink" title="安装hexo"></a>安装hexo</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-cli -g</span><br></pre></td></tr></table></figure>
<ul>
<li>在任意文件夹下，执行以下命令，注意如果是为hexo.git,那么会生成一个hexo文件夹<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> 用户名@服务器ip:/路径/.git</span><br></pre></td></tr></table></figure></li>
<li>进入到克隆到的文件夹内，执行：<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install</span><br><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure>
<div class="note info flat"><p>npm install的作用？<br>每一个rn项目都有一个package.json文件，里面有很多组件信息<br>使用npm install将按照package.json安装所需要的组件放在生成的node_modules文件夹中<br>rn项目下的每一个文件中都可以通过import引入node_modules的组件来加以使用</p>
</div>

</li>
</ul>
<h3 id="hexo-command-not-found"><a href="#hexo-command-not-found" class="headerlink" title="hexo: command not found"></a>hexo: command not found</h3><p>如果在命令行下直接使用hexo命令提示该命令无法找到时，可能原因是node_modules下的.bin文件夹没有添加进系统环境变量PATH<br><img src="6%E3%80%81%E5%B0%86node_modules%E6%B7%BB%E5%8A%A0%E8%BF%9B%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E4%B8%AD.png" alt="将node_modules添加进环境变量中"></p>
<h2 id="生成与部署"><a href="#生成与部署" class="headerlink" title="生成与部署"></a>生成与部署</h2><p>在该文件夹内的package.json可以添加脚本，如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;scripts&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;d&quot;</span>: <span class="string">&quot;hexo clean &amp;&amp;  hexo g -d &amp;&amp; git status &amp;&amp; git add -A &amp;&amp; git commit -m &#x27;auto&#x27; &amp;&amp; git push&quot;</span></span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure>
<div class="note warning flat"><p>这里的scripts在package.json 中已经有，增加属性即可，这里是新增了一个命令d，那么在使用时需要执行的命令为<code>npm run d</code>，这样就可以直接一键部署到服务器顺带也将源文件也同步到远程仓库中</p>
</div>

<div class="note info flat"><p>如果A和B都有clone仓库，而且在电脑A修改过源文件并且已经push到服务器，在电脑B上就需要先git pull一下，再进行博客编写</p>
</div>

<h1 id="收尾"><a href="#收尾" class="headerlink" title="收尾"></a>收尾</h1><p>到这里整个hexo搭建算是完成了，最后是将普通用户的shell登录操作禁止掉，仅可以git操作。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">// 如果不是root用户请切换至root用户</span><br><span class="line">su root</span><br><span class="line">// 查看 git-shell 是否在登录方式里面</span><br><span class="line">cat /etc/shells </span><br><span class="line">// 查看是否安装</span><br><span class="line"><span class="built_in">which</span> git-shell </span><br><span class="line">vi /etc/shells</span><br><span class="line">// 添加上2步显示出来的路劲，通常在 /usr/bin/git-shell</span><br></pre></td></tr></table></figure>
<p><img src="4%E3%80%81%E6%B7%BB%E5%8A%A0git-shell.png" alt="添加git-shell"><br><img src="5%E3%80%81%E7%BC%96%E8%BE%91shells%E6%96%87%E4%BB%B6.png" alt="编辑shells文件"></p>
<p>修改<code>/etc/passwd</code>中的权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 修改passwd文件</span><br><span class="line">vi /etc/passwd</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 将原来的</span><br><span class="line">git:x:1000:1000::/home/caixianquan:/bin/bash</span><br><span class="line"></span><br><span class="line">// 修改为</span><br><span class="line">git:x:1000:1000::/home/caixianquan:/bin/git-shell</span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Cai XianQuan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://xquan123.gitee.io/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/">https://xquan123.gitee.io/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xquan123.gitee.io" target="_blank">Cquang博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/git/">git</a><a class="post-meta__tags" href="/blog/tags/hexo/">hexo</a><a class="post-meta__tags" href="/blog/tags/ssh/">ssh</a></div><div class="post_share"><div class="social-share" data-image="/blog/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C%E9%A6%96%E9%A1%B5.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2020/07/19/Python%E5%9F%BA%E7%A1%80/"><img class="prev-cover" src="/blog/2020/07/19/Python%E5%9F%BA%E7%A1%80/Python%E5%9F%BA%E7%A1%80%E9%A6%96%E9%A1%B5.jpg" onerror="onerror=null;src='/blog/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Python基础</div></div></a></div><div class="next-post pull-right"><a href="/blog/2020/06/29/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%B8%80/"><img class="next-cover" src="/blog/2020/06/29/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%B8%80/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%B8%80%E9%A6%96%E9%A1%B5.png" onerror="onerror=null;src='/blog/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">hexo+nginx服务器上部署博客(一)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2020/06/29/hexo-nginx服务器上部署博客-一/" title="hexo+nginx服务器上部署博客(一)"><img class="cover" src="/blog/2020/06/29/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%B8%80/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%B8%80%E9%A6%96%E9%A1%B5.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-06-29</div><div class="title">hexo+nginx服务器上部署博客(一)</div></div></a></div><div><a href="/blog/2020/08/16/Git知识点及问题收集/" title="Git知识点及问题收集"><img class="cover" src="/blog/2020/08/16/Git%E7%9F%A5%E8%AF%86%E7%82%B9%E5%8F%8A%E9%97%AE%E9%A2%98%E6%94%B6%E9%9B%86/Git%E7%9F%A5%E8%AF%86%E7%82%B9%E5%8F%8A%E9%97%AE%E9%A2%98%E6%94%B6%E9%9B%86%E9%A6%96%E9%A1%B5.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-16</div><div class="title">Git知识点及问题收集</div></div></a></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" src="/blog/img/%E5%A4%B4%E5%83%8F.gif" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Cai XianQuan</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">22</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">33</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div></div><a class="button--animated" id="card-info-btn" href="javascript:;"><i class="fab fa-bookmark"></i><span>加入书签</span></a></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">一花一世界,一木一菩提╮(￣▽ ￣)╭</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%9C%AC%E7%AB%A0%E9%87%8D%E7%82%B9"><span class="toc-number">1.</span> <span class="toc-text">本章重点</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#ssh%E5%85%8D%E5%AF%86%E7%99%BB%E5%BD%95"><span class="toc-number">2.</span> <span class="toc-text">ssh免密登录</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#root%E4%B8%8B%E5%85%8D%E5%AF%86%E7%99%BB%E5%BD%95"><span class="toc-number">2.1.</span> <span class="toc-text">root下免密登录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%99%AE%E9%80%9A%E8%B4%A6%E6%88%B7%E4%B8%8B%E5%85%8D%E5%AF%86%E7%99%BB%E5%BD%95"><span class="toc-number">2.2.</span> <span class="toc-text">普通账户下免密登录</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%9B%E5%BB%BAgit%E4%BB%93%E5%BA%93%EF%BC%8C%E9%85%8D%E7%BD%AEhooks"><span class="toc-number">3.</span> <span class="toc-text">创建git仓库，配置hooks</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Hexo"><span class="toc-number">4.</span> <span class="toc-text">安装Hexo</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85hexo"><span class="toc-number">4.1.</span> <span class="toc-text">安装hexo</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%80%E4%B8%AA-Hexo-%E5%8D%9A%E5%AE%A2"><span class="toc-number">4.2.</span> <span class="toc-text">初始化一个 Hexo 博客</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E4%B8%BB%E9%A2%98%EF%BC%8Chexo%E4%BC%98%E5%8C%96"><span class="toc-number">4.3.</span> <span class="toc-text">安装主题，hexo优化</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%83%A8%E7%BD%B2hexo%E5%B9%B6%E5%8F%91%E5%B8%83"><span class="toc-number">5.</span> <span class="toc-text">部署hexo并发布</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9C%A8%E6%96%B0%E7%94%B5%E8%84%91%E4%B8%8A%E7%BB%A7%E7%BB%AD%E4%BD%BF%E7%94%A8hexo"><span class="toc-number">6.</span> <span class="toc-text">在新电脑上继续使用hexo</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AF%B4%E6%98%8E"><span class="toc-number">6.1.</span> <span class="toc-text">说明</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E9%9D%9E%E8%A3%B8%E4%BB%93%E5%BA%93"><span class="toc-number">6.2.</span> <span class="toc-text">创建非裸仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8A%E4%BC%A0%E5%88%B0%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="toc-number">6.3.</span> <span class="toc-text">上传到远程仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8%E6%96%B0%E7%94%B5%E8%84%91%E4%B8%8A%E5%AE%89%E8%A3%85git%E5%92%8Cnodejs"><span class="toc-number">6.4.</span> <span class="toc-text">在新电脑上安装git和nodejs</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85hexo-1"><span class="toc-number">6.5.</span> <span class="toc-text">安装hexo</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#hexo-command-not-found"><span class="toc-number">6.5.1.</span> <span class="toc-text">hexo: command not found</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%9F%E6%88%90%E4%B8%8E%E9%83%A8%E7%BD%B2"><span class="toc-number">6.6.</span> <span class="toc-text">生成与部署</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%94%B6%E5%B0%BE"><span class="toc-number">7.</span> <span class="toc-text">收尾</span></a></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/01/29/%E6%A1%86%E6%9E%B6%E5%A5%97%E8%B7%AF%E8%A7%A3%E7%AE%97%E6%B3%95/" title="框架套路解算法"><img src="/blog/2021/01/29/%E6%A1%86%E6%9E%B6%E5%A5%97%E8%B7%AF%E8%A7%A3%E7%AE%97%E6%B3%95/%E6%A1%86%E6%9E%B6%E5%A5%97%E8%B7%AF%E8%A7%A3%E7%AE%97%E6%B3%95%E9%A6%96%E9%A1%B5.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="框架套路解算法"/></a><div class="content"><a class="title" href="/blog/2021/01/29/%E6%A1%86%E6%9E%B6%E5%A5%97%E8%B7%AF%E8%A7%A3%E7%AE%97%E6%B3%95/" title="框架套路解算法">框架套路解算法</a><time datetime="2021-01-29T07:37:55.000Z" title="发表于 2021-01-29 15:37:55">2021-01-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/01/07/shell%E8%84%9A%E6%9C%AC%E5%AD%A6%E4%B9%A0/" title="shell脚本学习"><img src="/blog/2021/01/07/shell%E8%84%9A%E6%9C%AC%E5%AD%A6%E4%B9%A0/shell%E8%84%9A%E6%9C%AC%E5%AD%A6%E4%B9%A0%E9%A6%96%E9%A1%B5.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="shell脚本学习"/></a><div class="content"><a class="title" href="/blog/2021/01/07/shell%E8%84%9A%E6%9C%AC%E5%AD%A6%E4%B9%A0/" title="shell脚本学习">shell脚本学习</a><time datetime="2021-01-07T03:29:18.000Z" title="发表于 2021-01-07 11:29:18">2021-01-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/12/28/Linux%E9%97%AE%E9%A2%98%E9%9B%86%E9%94%A6/" title="Linux问题集锦"><img src="/blog/2020/12/28/Linux%E9%97%AE%E9%A2%98%E9%9B%86%E9%94%A6/Linux%E9%97%AE%E9%A2%98%E9%9B%86%E9%94%A6%E9%A6%96%E9%A1%B5.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Linux问题集锦"/></a><div class="content"><a class="title" href="/blog/2020/12/28/Linux%E9%97%AE%E9%A2%98%E9%9B%86%E9%94%A6/" title="Linux问题集锦">Linux问题集锦</a><time datetime="2020-12-28T01:56:38.000Z" title="发表于 2020-12-28 09:56:38">2020-12-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/12/13/%E5%B8%B8%E7%94%A8%E7%9A%84Linux%E5%91%BD%E4%BB%A4%E9%9B%86/" title="常用的Linux命令集"><img src="/blog/2020/12/13/%E5%B8%B8%E7%94%A8%E7%9A%84Linux%E5%91%BD%E4%BB%A4%E9%9B%86/%E5%B8%B8%E7%94%A8%E7%9A%84Linux%E5%91%BD%E4%BB%A4%E9%9B%86%E9%A6%96%E9%A1%B5.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="常用的Linux命令集"/></a><div class="content"><a class="title" href="/blog/2020/12/13/%E5%B8%B8%E7%94%A8%E7%9A%84Linux%E5%91%BD%E4%BB%A4%E9%9B%86/" title="常用的Linux命令集">常用的Linux命令集</a><time datetime="2020-12-13T14:32:23.000Z" title="发表于 2020-12-13 22:32:23">2020-12-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/12/13/Flink%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/" title="Flink入门学习"><img src="/blog/2020/12/13/Flink%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/Flink%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0%E9%A6%96%E9%A1%B5.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Flink入门学习"/></a><div class="content"><a class="title" href="/blog/2020/12/13/Flink%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/" title="Flink入门学习">Flink入门学习</a><time datetime="2020-12-13T10:21:57.000Z" title="发表于 2020-12-13 18:21:57">2020-12-13</time></div></div></div></div></div></div></div></main><footer id="footer" style="background-image: url(/blog/2020/07/03/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C/hexo-nginx%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%E5%8D%9A%E5%AE%A2-%E4%BA%8C%E9%A6%96%E9%A1%B5.jpg)"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By Cai XianQuan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi,  welcome  to  my  <a  target="_blank" rel="noopener" href="https://www.caixianquan.tk">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="/blog/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/blog/js/search/local-search.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/js/bookmark.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script></div></body></html>